<template>
  <el-dialog :title="'支付'" :close-on-click-modal="false" :visible.sync="visible" :append-to-body="true">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="其他" name="one">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">

          <el-form-item label="支付金额" prop="payPrice">
            <el-input v-model="dataForm.payPrice" placeholder="金额"></el-input>
          </el-form-item>

          <el-form-item label="备注" prop="remarks">
            <el-input type="textarea" :rows="2" v-model="dataForm.remarks" placeholder="备注"></el-input>
          </el-form-item>
        </el-form>

        <span class="dialog-footer">
          <el-checkbox v-model="payPrintCheck" style="margin-right: 10px;">打印支付单</el-checkbox>
          <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
          <el-button type="primary" @click="dataFormSubmit2">{{ $t('Common.Confirm') }}</el-button>
        </span>
      </el-tab-pane>
      <el-tab-pane label="客房" name="first">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
          <el-form-item size="small" label="收款账号">
            <el-select v-model="dataForm.peopleId" prop="peopleId" filterable remote @change="changePeopleId"
              reserve-keyword placeholder="房间号/姓名" :remote-method="accPeoRemoteMethod" :loading="remoteMethodLoading">
              <el-option v-for="item in accPeoOptions" :key="item.id" :label="item.roomSign +item.roomNum +' / ' + item.name + ' / '+ (item.state == 1 ? '正常入住':'未结退房')"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item size="small" label="支付方式">
            <el-select v-model="dataForm.nowType" disabled placeholder="请选择">
              <el-option v-for="item in options.paysTypeOptions" :key="item.name" :label="item.name" :value="item.id"></el-option>
            </el-select>
            <el-button size="small" class="in_block" v-if="state == 1" @click="state = 2">取消押金</el-button>
            <el-button size="small" class="in_block" v-else @click="state = 1">标记押金</el-button>
          </el-form-item>
          <el-form-item size="small" label="金额" prop="payPrice">
            <el-input style="width: 199px;" v-model="dataForm.payPrice" placeholder="金额"></el-input>
            <el-tag type="danger" v-if="state == 1">押</el-tag>
          </el-form-item>
          <el-form-item label="备注" prop="remarks">
            <el-input type="textarea" :rows="2" v-model="dataForm.remarks" placeholder="备注"></el-input>
          </el-form-item>
        </el-form>
        <span class="dialog-footer">
          <el-checkbox v-model="printShouKuanCheck" style="margin-right: 10px;">打印收款单</el-checkbox>
          <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
          <el-button type="primary" @click="dataFormSubmit(0)">{{ $t('Common.Confirm') }}</el-button>
        </span>
      </el-tab-pane>
    </el-tabs>

    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" title="请扫描二维码" :visible.sync="payVisible"
      width="30%" append-to-body>
      <div v-loading="payLoding" element-loading-text="正在执行支付">
        <div style="  display: flex;
      justify-content: center;
      align-items: center;margin-bottom:10px">
          <img src="../../../../assets/img/barCode.jpg" />
        </div>

        <div style="text-align:center">支持微信或支付宝条码支付</div>
        <div style="text-align:center">请用条码枪进行扫描</div>
        <span>
          <el-input v-model="auth_no" placeholder="请扫描二维码,支持微信支付宝" @keyup.enter.native="authClose" ref="inputFocus"></el-input>
        </span>
      </div>
    </el-dialog>

    <t7 v-show="false" id="t7" :note="this.printconfig.note" :info="this.infoSet" :priceMap="this.priceMap" :currData="this.currData"
      :row-data="rowData" ref="t7"></t7>
    <t8 v-show="false" id="t8" :note="this.printconfig.note" :info="this.infoSet" :priceMap="this.priceMap" :currData="this.currData"
      :row-data="rowData" ref="t8"></t8>
    <t9 v-show="false" id="t9" :note="this.printconfig.note" :info="this.infoSet" :priceMap="this.priceMap" :currData="this.currData"
      :row-data="rowData" ref="t9"></t9>

    <pay58 v-show="false" id="pay58" ref="pay58"></pay58>
    <pay80 v-show="false" id="pay80" ref="pay80"></pay80>
    <payA5 v-show="false" id="payA5" ref="payA5"></payA5>
  </el-dialog>
</template>

<script>
  import moment from 'moment';
  import t7 from '../../../common/printtemplate/shoukuan_58mm';
  import t8 from '../../../common/printtemplate/shoukuan_80mm';
  import t9 from '../../../common/printtemplate/shoukuan_A5';
  import pay58 from '../../../common/printtemplate/pay_58mm';
  import pay80 from '../../../common/printtemplate/pay_80mm';
  import payA5 from '../../../common/printtemplate/pay_A5';
  import {
    getLodop
  } from '../../../../utils/lodop';
  export default {
    data() {
      return {
        infoSet: {
          peopleEntity:{
            name:'',
          },
        },
        priceMap: {},
        paySign: '',
        currData: '',
        remoteMethodLoading: false,
        accPeoOptions: [],
        payPrintCheck: false,
        printTuiKuanCheck: false,
        printShouKuanCheck: false,
        state: 2,
        dataListLoading: false,
        fukuan: 2,
        refundableAmountVisible: false,
        refundableAmount: 0,
        payTypeSign: 0,
        dataList: [],
        refundableAmountList: [],
        shopDataList: [],
        options: {
          paysTypeOptions: [],
          peopleOptions: []
        },
        payLoding: false,
        timer: null,
        dataForm: {
          id: 0,
          sellerId: '',
          consumeId: '',
          payType: '',
          creatTime: '',
          payPrice: 0,
          banks: '',
          banksNumber: '',
          referenceNumber: '',
          termValidity: '',
          peopleId: '',
          remarks: '',
          nowType: '',
          type: ''
        },
        printconfig: {},
        printconfig3: {},
        rowData: {},
        dataRule: {
          sellerId: [{
            required: true,
            message: '商家不能为空',
            trigger: 'blur'
          }],
          peopleId: [{
            required: true,
            message: '收款人不可为空',
            trigger: 'blur'
          }]
        },
        activeName: 'one',
        visible: false,
        info: {},
        payInterfaceConfig: {}, //支付
        payVisible: false,
        auth_no: '',
        countnum: 0
      };
    },
    components: {
      t7,
      t8,
      t9,
      pay58,
      pay80,
      payA5,
    },
    methods: {
      changePeopleId(val) {
        if (this.dataForm.peopleId) {
          this.getInfo(this.dataForm.peopleId);
        } else {
          this.infoSet = {};
        }
      },
      getInfo(peopleId) {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinsingle/pop_single/${peopleId}`),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.infoSet.peopleEntity = data.data.peopleEntity;
            if (data.data.peopleEntity.state != 4) {
              this.priceMap = data.data.priceMap;
              this.currData = this.priceMap[moment(this.infoSet.peopleEntity.arrivalsTime).format('YYYY-MM-DD')];
              this.infoSet.peopleEntity = {
                ...this.infoSet.peopleEntity,
                newArrivalsTime: moment(this.infoSet.peopleEntity.arrivalsTime).format('MM/DD HH:mm'),
                newPredissociationTime: moment(this.infoSet.peopleEntity.predissociationTime).format(
                  'MM/DD HH:mm')
              };
              console.log(this.infoSet.peopleEntity);

              this.infoSet.floorRoomEntity = data.data.floorRoomEntity;
              this.infoSet.roomEntity = data.data.roomEntity;
            }
            this.infoSet.singleEntity = data.data.singleEntity;
          }
        });
      },
      accPeoRemoteMethod(query) {
        if (query !== '') {
          this.remoteMethodLoading = true;
          //远程查询
          this.$http({
            url: this.$http.adornUrl("/hotel/thotelfloorroomcheckinpeople/list"),
            params: this.$http.adornParams({
              page: 1,
              limit: 999,
              key: query,
            }),
            method: "GET"
          }).then(({
            data
          }) => {
            if (data && data.code === 0) {
              console.log(data.page);
              this.accPeoOptions = data.page.list;
            } else {
              this.accPeoOptions = [];
            }
            this.remoteMethodLoading = false;
          });
        } else {
          this.accPeoOptions = [];
        }
      },
      loadPrintConfig() {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelprinttemplate/info/3`),
          method: 'get'
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.printconfig = data.tHotelPrintTemplate;
          } else {
            this.$message.error(data.msg);
          }
        });
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelprinttemplate/info/8`),
          method: 'get'
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.printconfig3 = data.tHotelPrintTemplate;
          } else {
            this.$message.error(data.msg);
          }
        });
      },
      shopChange(counts) {
        //计算价格
        this.countnum = counts;
        var money = 0;
        this.shopDataList.forEach(item => {
          var count = item.count;
          var salePrice = item.salePrice;
          money += count * salePrice;
        });
        this.dataForm.payPrice = money;
      },
      consumeChange() {
        this.getShopDataList();
      },
      // 获取数据列表
      getShopDataList() {
        this.dataListLoading = true;
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorroomconsumeshop/list'),
          method: 'get',
          params: this.$http.adornParams({
            page: 1,
            limit: 999,
            parentId: this.dataForm.consumeId,
            state: 1,
            key: this.dataForm.key
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.shopDataList = data.page.list.map(item => ({
              ...item,
              count: 0
            }));
          } else {
            this.shopDataList = [];
          }
          this.dataListLoading = false;
        });
      },
      // 获取数据列表
      getDataList() {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorroomconsume/list'),
          method: 'get',
          params: this.$http.adornParams({
            page: 1,
            limit: 999,
            parentId: 0
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list;
            console.log(this.dataList);
          } else {
            this.dataList = [];
          }
        });
      },
      init() {
        this.visible = true;
        this.info = {};
        this.loadPrintConfig();
        this.getPayInterface();
        this.getDataList();
        this.$forceUpdate();
        if (this.$cookie.get('printShouKuanCheck') != null) {
          if (this.$cookie.get('printShouKuanCheck') == 1) {
            this.printShouKuanCheck = true
          } else {
            this.printShouKuanCheck = false
          }
        }
        if (this.$cookie.get('printTuiKuanCheck') != null) {
          if (this.$cookie.get('printTuiKuanCheck') == 1) {
            this.printTuiKuanCheck = true
          } else {
            this.printTuiKuanCheck = false
          }
        }
        if (this.$cookie.get('payPrintCheck') != null) {
          if (this.$cookie.get('payPrintCheck') == 1) {
            this.payPrintCheck = true
          } else {
            this.payPrintCheck = false
          }
        }
        this.$nextTick(() => {
          this.getPayTypes();
        });
      },
      //获取支付方式
      getPayTypes() {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorroompaytype/list'),
          method: 'get',
          params: this.$http.adornParams({
            page: 1,
            limit: 999,
            state: 1
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.options.paysTypeOptions = data.page.list;
            if (this.payInterfaceConfig) {
              this.dataForm.nowType = this.payInterfaceConfig.payTypeId
            } else {
              this.dataForm.nowType = this.options.paysTypeOptions[0].id;
            }
          } else {
            this.options.paysTypeOptions = [];
          }
        });
      },
      //获取入账账号
      getPeopls() {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinsingle/pop_people/${this.info.singleId}`),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.options.peopleOptions = data.data;
          } else {
            this.options.peopleOptions = [];
          }
        });
      },
      handleClick(tab, res) {
        console.log(tab, res)
      },
      getPayInterface() {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelsellerpayinterfaceconfig/myInfo`),
          method: 'get'
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.payInterfaceConfig = data.tHotelSellerPayInterfaceConfig
          } else {
            this.$message.error("加载支付配置失败")
          }
        })
      },
      printSK() {

        this.$forceUpdate();
        this.$nextTick(() => {
          setTimeout(() => {
            LODOP = getLodop();
            if (!LODOP) {
              this.$alert(
                `<br><font color='#FF00FF'>CLodop云打印服务(localhost本地)未安装启动!点击这里<a href='http://www.lodop.net/download/CLodop_Setup_for_Win32NT_4.088Extend.zip' download target='_self'>执行安装</a>,安装后请刷新页面。</font>`,
                '安装', {
                  confirmButtonText: '确定',
                  dangerouslyUseHTMLString: true
                }
              );
              return;
            }

            //样式
            var strStyleCSS =
              " <link href='https://ebooking.qlan99.com/css/print.css' type='text/css' rel='stylesheet'> ";

            var olstyle1 = '<!DOCTYPE html><html lang="zh-CN"><head>' + strStyleCSS + '</head>' + ' <style> ' +
              'div{border:0!important}' + '</style>';
            var body = '';
            if (this.printconfig.specs === '58mm') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (58 + parseInt(this.printconfig.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.t7.$refs.t7.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 580, 3000, ''); //设定纸张大小
            }
            if (this.printconfig.specs === '80mm') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (80 + parseInt(this.printconfig.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.t8.$refs.t8.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 800, 2500, ''); //设定纸张大小
            }
            if (this.printconfig.specs === 'A5') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (210 + parseInt(this.printconfig.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.t9.$refs.t9.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 2100, 2000, ''); //设定纸张大小
            }
            body += '</html>';
            LODOP.ADD_PRINT_HTM(0, 0, 1000, 2000, body); //增加超文本项

            LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', '100%'); //设置缩放
            // LODOP.PRINT_INIT('订单') //打印初始化
            LODOP.SET_PRINT_STYLE('FontSize', 12); //设置对象风格
            LODOP.SET_PRINT_STYLE('Bold', 1); ////设置对象风格
            LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, ''); //设置窗口
            LODOP.SET_PRINT_COPIES(this.printconfig.printSum);

            LODOP.SET_LICENSES("", "4B44F795076C8F14211A5ED0A5339305DAB", "23580B189D96F33252722697A57AC00506B",
              "");

            if (this.printconfig.preview) {
              if (LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint)) {
                LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint);
                LODOP.PRINT();
                // LODOP.PRINT_DESIGN();
              } else {
                LODOP.SET_PRINTER_INDEXA(0);
                LODOP.PRINT();
                // LODOP.PRINT_DESIGN();
              }
            } else {
              if (LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint)) {
                LODOP.SET_PRINTER_INDEXA(this.printconfig.defaultPrint);
                LODOP.PREVIEW();
              } else {
                LODOP.SET_PRINTER_INDEXA(0);
                LODOP.PREVIEW();
                // LODOP.PRINT_DESIGN();
              }
            }
          }, 100)

        });
      },
      printPay() {
        this.$nextTick(() => {
          setTimeout(() => {
            LODOP = getLodop();
            if (!LODOP) {
              this.$alert(
                `<br><font color='#FF00FF'>CLodop云打印服务(localhost本地)未安装启动!点击这里<a href='http://www.lodop.net/download/CLodop_Setup_for_Win32NT_4.088Extend.zip' download target='_self'>执行安装</a>,安装后请刷新页面。</font>`,
                '安装', {
                  confirmButtonText: '确定',
                  dangerouslyUseHTMLString: true
                }
              );
              return;
            }

            //样式
            var strStyleCSS =
              " <link href='https://ebooking.qlan99.com/css/print.css' type='text/css' rel='stylesheet'> ";

            var olstyle1 = '<!DOCTYPE html><html lang="zh-CN"><head>' + strStyleCSS + '</head>' + ' <style> ' +
              'div{border:0!important}' + '</style>';
            var body = '';
            if (this.printconfig3.specs === '58mm') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (58 + parseInt(this.printconfig3.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.pay58.$refs.pay58.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 580, 3000, ''); //设定纸张大小
            }
            if (this.printconfig3.specs === '80mm') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (80 + parseInt(this.printconfig3.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.pay80.$refs.pay80.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 800, 2500, ''); //设定纸张大小
            }
            if (this.printconfig3.specs === 'A5') {
              var olstyle2 = '<style> .print-wrap-normal{width:' + (210 + parseInt(this.printconfig3.printContentOffset)) +
                'mm  !important}</style>';
              body = olstyle1 + olstyle2 + '<body>' + this.$refs.payA5.$refs.payA5.innerHTML + '</body>';
              LODOP.SET_PRINT_PAGESIZE(0, 2100, 2000, ''); //设定纸张大小
            }
            body += '</html>';
            LODOP.ADD_PRINT_HTM(0, 0, 1000, 2000, body); //增加超文本项

            LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', '100%'); //设置缩放
            // LODOP.PRINT_INIT('订单') //打印初始化
            LODOP.SET_PRINT_STYLE('FontSize', 12); //设置对象风格
            LODOP.SET_PRINT_STYLE('Bold', 1); ////设置对象风格
            LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, ''); //设置窗口
            LODOP.SET_PRINT_COPIES(this.printconfig3.printSum);

            LODOP.SET_LICENSES("", "4B44F795076C8F14211A5ED0A5339305DAB", "23580B189D96F33252722697A57AC00506B",
              "");

            if (this.printconfig3.preview) {
              if (LODOP.SET_PRINTER_INDEXA(this.printconfig3.defaultPrint)) {
                LODOP.SET_PRINTER_INDEXA(this.printconfig3.defaultPrint);
                LODOP.PRINT();
                // LODOP.PRINT_DESIGN();
              } else {
                LODOP.SET_PRINTER_INDEXA(0);
                LODOP.PRINT();
                // LODOP.PRINT_DESIGN();
              }
            } else {
              if (LODOP.SET_PRINTER_INDEXA(this.printconfig3.defaultPrint)) {
                LODOP.SET_PRINTER_INDEXA(this.printconfig3.defaultPrint);
                LODOP.PREVIEW();
              } else {
                LODOP.SET_PRINTER_INDEXA(0);
                LODOP.PREVIEW();
                // LODOP.PRINT_DESIGN();
              }
            }
          }, 100)

        });
      },
      dataFormSubmit2() {
        if (this.dataForm.payPrice <= 0) {
          this.$message.error("支付金额需大于0")
          return false
        }
        if (this.payPrintCheck) {
          this.$cookie.set('payPrintCheck', 1)
        } else {
          this.$cookie.set('payPrintCheck', 2)
        }
        this.payVisible = true;
        this.paySign = 3;
        this.changeFocus();
      },
      // 表单提交
      dataFormSubmit(type) {
        if (!this.dataForm.peopleId) {
          this.$message.error("请选择收款账号")
          return false
        }
        this.$refs['dataForm'].validate(valid => {
          if (valid) {
            this.paySign = 1;
            if (this.dataForm.payPrice <= 0) {
              this.$message.error(type == 5 ? "退款金额需大于0" : "收款金额需大于0")
              return false
            }
            
            if (this.printShouKuanCheck) {
              this.$cookie.set('printShouKuanCheck', 1)
            } else {
              this.$cookie.set('printShouKuanCheck', 2)
            }

            var flag = false;
            if (type == 5 || type == 0) {
              flag = true;
            }
            
            if (this.payInterfaceConfig.switchConfig == 1 && flag) {
              if (this.payInterfaceConfig.payTypeId === this.dataForm.nowType) {
                if (type == 5) {
                  if (this.dataForm.payPrice > this.refundableAmount) {
                    this.$message.error("退款金额不可超过已授权可退金额")
                    return
                  } else {
                    this.$http({
                      url: this.$http.adornUrl(
                        `/hotel/thotelfloorroomcheckinpeople/view_ysq_finish/${this.dataForm.peopleId}`),
                      method: 'get',
                      params: this.$http.adornParams({
                        amount: this.dataForm.payPrice
                      })
                    }).then(({
                      data
                    }) => {
                      this.refundableAmountVisible = true;
                      if (data && data.code === 0) {
                        Object.assign(this.$data, this.$options.data());
                        this.$message({
                          message: this.$t('Common.OperationSuccessful'),
                          type: 'success',
                          duration: 1500,
                          onClose: () => {
                            this.visible = false;
                            this.$emit('refreshDataList');
                          }
                        });
                      } else {
                        this.$message.error(data.msg)
                      }
                    })
                  }
                  return
                } else {
                  this.payVisible = true;
                  this.payTypeSign = type;
                  this.changeFocus();
                  return
                }
              }
            }

            this.$http({
              url: this.$http.adornUrl(
                `/hotel/thotelfloorroomcheckinaccounting/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                payType: type,
                payPrice: this.dataForm.payPrice,
                banks: this.dataForm.banks,
                banksNumber: this.dataForm.banksNumber,
                referenceNumber: this.dataForm.referenceNumber,
                consumeId: this.dataForm.consumeId,
                termValidity: this.dataForm.termValidity,
                peopleId: this.dataForm.peopleId,
                remarks: this.dataForm.remarks,
                nowType: this.dataForm.nowType,
                fukuan: this.fukuan,
                flooroomid: this.info.floorRoomId,
                ruzhuno: this.info.ruzhuNo,
                state: this.state,
                submitType: 1,
                sign: JSON.stringify(this.shopDataList.filter(item => item.count > 0)),
                type: 0
              })
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                
                this.visible = false;
                
                this.$nextTick(() => {
                  this.$emit('refreshDataList');
                });

                if (this.printShouKuanCheck) {
                  var rowData = data.accounting
                  this.$refs.t7.setRowData(rowData);
                  this.$refs.t8.setRowData(rowData);
                  this.$refs.t9.setRowData(rowData);
                }

                this.$message({
                  message: this.$t('Common.OperationSuccessful'),
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    if (this.printShouKuanCheck) {
                      this.printSK()
                    }
                  }
                });

              } else {
                this.$message.error(data.msg)
              }
            });
          }
        });
      },
      authClose() {
        if (this.paySign == 1) {
          this.payLoding = true;

          //扫码支付请求数据
          this.$http({
            url: this.$http.adornUrl('/hotel/thotelsellerpayinterfaceconfig/preAuthBar'),
            method: 'post',
            data: this.$http.adornData({
              'type': 2, //正式
              'auth_no': this.auth_no, //授权码，客户的付款码
              'total_fee': this.dataForm.payPrice * 100, //金额，单位分
              'order_body': '测试', //订单描述
              'attach': '测试', //附加数据,原样返回
            })
          }).then(({
            data
          }) => {
            if (data && data.code === 0) {
              this.payVisible = false
              //保存入账信息
              this.auth_no = "";
              this.payLoding = false;
              var terminalTrace = data.data.terminalTrace
              this.authSubForm(terminalTrace);
            } else if (data.code == 3) {
              //循环查询订单，直至成功或失败
              this.timer = setInterval(() => {
                this.queryOrder(data.data);
              }, 1500);
            } else {
              this.payLoding = false;
              this.auth_no = "";
              this.payVisible = false
              this.$message.error(data.msg);
            }
          })
        }
        if (this.paySign == 3) {
          this.payLoding = true;
          //扫码支付请求数据
          this.$http({
            url: this.$http.adornUrl('/hotel/thotelsellerpayinterfaceconfig/preAuthBar'),
            method: 'post',
            data: this.$http.adornData({
              'type': 2, //正式
              'auth_no': this.auth_no, //授权码，客户的付款码
              'total_fee': this.dataForm.payPrice * 100, //金额，单位分
              'order_body': '测试', //订单描述
              'attach': '测试', //附加数据,原样返回
              'remarks': this.dataForm.remarks,
              'paySourceSign': 3,
            })
          }).then(({
            data
          }) => {
            if (data && data.code === 0) {
              this.payVisible = false
              //保存入账信息
              this.auth_no = "";
              this.payLoding = false;
              this.qitaSuccess(data.data);
            } else if (data.code == 3) {
              //循环查询订单，直至成功或失败
              this.timer = setInterval(() => {
                this.queryOrder2(data.data);
              }, 1500);
            } else {
              this.payLoding = false;
              this.auth_no = "";
              this.payVisible = false
              this.$message.error(data.msg);
            }
          })
        }

      },
      queryOrder(data) {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsellerpayinterfaceconfig/commonQuery'),
          method: 'post',
          data: this.$http.adornData({
            'pay_type': data.payType,
            'terminal_trace': data.terminalTrace,
            'terminal_time': data.terminalTime,
            'out_trade_no': data.outTradeNo,
          })
        }).then(({
          data
        }) => {
          console.log(data)
          if (data && data.code === 0) {
            clearInterval(this.timer)
            this.payLoding = false;
            this.payVisible = false
            this.auth_no = "";
            //保存入账信息
            var terminalTrace = data.data.terminalTrace
            this.authSubForm(terminalTrace);
          } else if (data.code === 3) {

          } else {
            clearInterval(this.timer)
            this.payLoding = false;
            this.payVisible = false
            this.auth_no = "";
            this.$message.error(data.msg);
          }
        })
      },
      queryOrder2(data) {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsellerpayinterfaceconfig/commonQuery'),
          method: 'post',
          data: this.$http.adornData({
            'pay_type': data.payType,
            'terminal_trace': data.terminalTrace,
            'terminal_time': data.terminalTime,
            'out_trade_no': data.outTradeNo,
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            clearInterval(this.timer)
            this.payLoding = false;
            console.log(data)
            this.payVisible = false
            this.auth_no = "";
            this.qitaSuccess(data.data);

          } else if (data.code === 3) {

          } else {
            clearInterval(this.timer)
            this.payLoding = false;
            this.payVisible = false
            this.auth_no = "";
            this.$message.error(data.msg);
          }
        })
      },
      qitaSuccess(data) {
        this.$emit('refreshDataList');
        if (this.payPrintCheck) {
          this.$http({
            url: this.$http.adornUrl('/hotel/thotelpreauthbarresult/printing'),
            method: 'post',
            params: this.$http.adornParams({
              'terminalTrace': data.terminalTrace,
            })
          }).then(({
            data
          }) => {
            if (data && data.code === 0) {
              this.visible = false;

              var pdata = data.data
              this.$refs.pay58.setData(pdata);
              this.$refs.pay80.setData(pdata);
              this.$refs.payA5.setData(pdata);

              this.$message({
                message: this.$t('Common.OperationSuccessful'),
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.printPay();
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          })
        } else {
          this.visible = false;
          this.$message({
            message: this.$t('Common.OperationSuccessful'),
            type: 'success',
            duration: 1500,
            onClose: () => {

            }
          });
        }
      },
      authSubForm(terminalTrace) {
        this.$http({
          url: this.$http.adornUrl(
            `/hotel/thotelfloorroomcheckinaccounting/${!this.dataForm.id ? 'save' : 'update'}`),
          method: 'post',
          data: this.$http.adornData({
            collectionNo: terminalTrace,
            payType: this.payTypeSign,
            payPrice: this.dataForm.payPrice,
            banks: this.dataForm.banks,
            banksNumber: this.dataForm.banksNumber,
            referenceNumber: this.dataForm.referenceNumber,
            consumeId: this.dataForm.consumeId,
            termValidity: this.dataForm.termValidity,
            peopleId: this.dataForm.peopleId,
            remarks: this.dataForm.remarks,
            nowType: this.dataForm.nowType,
            state: this.state,
            fukuan: this.fukuan,
            submitType: 1,
            sign: JSON.stringify(this.shopDataList.filter(item => item.count > 0)),
            type: 0
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {

            this.visible = false;

            this.$nextTick(() => {
              this.$emit('refreshDataList');
            });

            if (this.printShouKuanCheck) {
              var rowData = data.accounting
              
              this.$refs.t7.setRowData(rowData);
              this.$refs.t8.setRowData(rowData);
              this.$refs.t9.setRowData(rowData);
            }

            this.$message({
              message: this.$t('Common.OperationSuccessful'),
              type: 'success',
              duration: 1500,
              onClose: () => {
                if (this.printShouKuanCheck) {
                  this.printSK()
                }
              }
            });

          } else {
            this.$message.error(data.msg);
          }
        });
      },
      changeFocus() {
        this.$nextTick(() => {
          this.$refs.inputFocus.focus();
        })

      }
    }
  };
</script>

<style></style>
